<template>
  <common-search-wrap @search="search" @reset="searchReset">
    <el-form ref="formRef" :inline="true" :model="formData">
      <el-form-item label="时间区间：" prop="times">
        <el-date-picker
          v-model="formData.times"
          type="daterange"
          range-separator="-"
          value-format="YYYY-MM-DD"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
        />
      </el-form-item>
    </el-form>
  </common-search-wrap>
</template>

<script setup>
import commonSearchWrap from "@/components/commonSearchWrap.vue";
import { reactive, onMounted } from "vue";
import useForm from '@/hooks/useForm'
import { threeMonthAgo, todayDate } from '@/utils/time'
const emits = defineEmits(['submit'])
/** 搜索的方法 */
const handleSearch = () => {
  let params = {}
  if (formData.times) {
    const [startDate, endDate] = formData.times
    Object.assign(params, { startDate, endDate })
  }
  emits('submit', params)
}
const { formRef, search, reset } = useForm(handleSearch)
const formData = reactive({
  times: [threeMonthAgo, todayDate],
});
const searchReset = () => {
  reset()
  handleSearch()
}
</script>